@echo off
setlocal

cd /d %~dp0

rem support use a proxy cache when test the setup scripts
if "%1" == "" (
	set distro=myproxy
) else (
	set distro=%1
)

set nexus=nexus-3.43.0-01-unix.tar.gz

if not exist %nexus% (
	echo you need download nexus-repository-OSS tar manual 
	echo from https://www.sonatype.com/products/repository-oss-download
	echo or from my baidu pan share https://pan.baidu.com/s/1nsKXvOS84TrndT4gnY88ZQ?pwd=wj4e
	goto :eof
)

if not exist ..\alpine.rootfs.tar.gz (
	curl https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/releases/aarch64/alpine-minirootfs-3.16.3-aarch64.tar.gz -o ..\alpine.rootfs.tar.gz
	rem or download from the alpine site
	rem curl https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/aarch64/alpine-minirootfs-3.16.3-aarch64.tar.gz -o ..\alpine.rootfs.tar.gz
)

if not exist ..\alpine.rootfs.tar.gz (
	echo alpine.rootfs.tar.gz not found and/or auto download failed
	echo you may download it manual and save to .seed\alpine.rootfs.tar.gz
	echo from https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/releases/aarch64/alpine-minirootfs-3.16.3-aarch64.tar.gz
	echo or https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/aarch64/alpine-minirootfs-3.16.3-aarch64.tar.gz
	goto :eof
)

if not exist ..\..\%distro% (
	mkdir ..\..\%distro% && wsl.exe --import %distro% ..\..\%distro% ..\alpine.rootfs.tar.gz --version 2 && mklink /H ..\..\%distro%.exe ..\distro.exe
)
wsl.exe -d %distro% -- tar xzf %nexus% -C ~ && ^
wsl.exe -d %distro% -- ./init-nexus.sh
